package com.pdg.mcplugin.recyclotron;

import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.PrepareItemCraftEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.Recipe;
import org.bukkit.inventory.ShapelessRecipe;
import com.pdg.mcplugin.common.baseclasses.PluginClientBase;

public class RecyclotronEventHander extends PluginClientBase<Recyclotron> implements Listener{

	private static final String FORMAT_INGREDIENT_NAME = "%s_%d";

	public RecyclotronEventHander(Recyclotron thePlugin) {
		super(thePlugin);
	}
	
	@EventHandler
	public void handlePrepareItemCraftEvent(PrepareItemCraftEvent theEvent){
		if(theEvent.isRepair()) return;
//		Player thePlayer = null;
//		if(theEvent.getView().getPlayer() instanceof Player){
//			thePlayer = (Player)theEvent.getView().getPlayer();
//		}else{
//			return;
//		}
		Recipe theRecipe = theEvent.getRecipe();
		if(theRecipe instanceof ShapelessRecipe){
			ShapelessRecipe theShapelessRecipe = (ShapelessRecipe)theRecipe;
			String theIngredientName = null;
			for(ItemStack theIngredient: theShapelessRecipe.getIngredientList()){
				String theCurrentIngredientName = String.format(FORMAT_INGREDIENT_NAME,theIngredient.getData().getItemType().toString(),theIngredient.getData().getData());
				if(theIngredientName==null){
					theIngredientName = theCurrentIngredientName;
				}else{
					if(!theIngredientName.equalsIgnoreCase(theCurrentIngredientName)){
						theIngredientName = null;
						break;
					}
				}
			}
			if(theIngredientName!=null){
				
			}
		}
	}

}
